﻿@using ABC.Controllers.ViewModels
@using ABC.Controllers.ViewModels.My
@using ABC.Controllers.ViewModels.My.News
@using ABC.Domain.Entities
@model MyTrashViewModel
@{
    ViewBag.Title = "Корзина - Азбука24";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
    var pagesize = Request.Params["pagesize"];
    var query = Request.Params["query"];
}
@functions {

    public static string GetUrl(string type, string id)
    {
        var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
        switch (type)
        {
            case "ФизическоеЛицо":
                return urlHelper.Action("Client", "Clients", new { id });
            case "ОбъектСтрахования":
                return urlHelper.Action("AddObject", "Cabinet", new { id });
            case "Партнер":
                return urlHelper.Action("FormPartner", "Admin", new { id });
            default:
                return "";
        }
    }

}
<script type="text/javascript">
    function Filter() {
        location.href = '@Url.Action("Trash", "Clients")?' + ($("#PageSize").val() != '@Model.ListForPageSize.First().Value' ? "pagesize=" + $("#PageSize").val() : "") +
            ($("#Query").val() ? "query=" + $("#Query").val() : "");
    }
    function ResetFilter() {
        location.href = '@Url.Action("Trash", "Clients", new { page = 1 })';
    }
    function ClearThrash() {
        location.href = '@Url.Action("ClearTrash", "Clients")?' + ($("#PageSize").val() != '@Model.ListForPageSize.First().Value' ? "&pagesize=" + $("#PageSize").val() : "") +
            ($("#Query").val() ? "query=" + $("#Query").val() : "");
    }
    function DeleteOrRestoreSelected(obj) {
        $("#action").val($(obj).attr("name"));
        $("#form1").submit();
    }
</script>
<div class="row-fluid">
    <!--// Левая колонка -->
    @{Html.RenderPartial("_SectionClientsMenu", new BaseViewModel());}
    <div class="span9">
        <div class="page-header">
            <h2>
                Корзина</h2>
        </div>
        <div class="row-fluid">
            <div class="span3">
                <div class="control-group">
                    <label class="control-label" for="Query">
                        Поиск</label>
                    <div class="controls">
                        @Html.TextBoxFor(x => x.Query, new { @class = "search-query input-medium" })
                    </div>
                </div>
            </div>
            <div class="span3">
            </div>
            <div class="span3">
            </div>
            <div class="span3">
                <div class="control-group">
                    <label class="control-label" for="phone-01">
                        Фильтр</label>
                    <div class="controls">
                        <div class="btn-group">
                            <button type="button" class="btn" onclick="Filter();">
                                Применить</button>
                            <button class="btn" rel="tooltip" data-original-title="Сбросить фильтр" onclick="ResetFilter();">
                                <i class="icon-refresh"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <table class="table table-bordered table-striped" id="clients">
            <thead>
                <tr>
                    <th class="col-1">
                        <input type="checkbox" id="inlineCheckbox01" onchange="ChangeAllCheck();" title="Выделить все">
                    </th>
                    <th>
                        Наименование
                    </th>
                    <th>
                        Дата создания
                    </th>
                    <th>
                        Дата удаления
                    </th>
                    <th>
                        Инструменты
                    </th>
                </tr>
            </thead>
            <tbody>
                @using (Html.BeginForm("DeleteOrRestoreTrashItems", "Clients", FormMethod.Post, new { id = "form1" }))
                {
                    @Html.Hidden("pagesize", Model.PageSize == 0 ? "" : Model.PageSize.ToString())
                    @Html.Hidden("query")
                    @Html.Hidden("page")
                    @Html.Hidden("action")
                    foreach (var deleteObj in Model.TrashItems)
                    {
                    <tr>
                        <td class="col-1">
                            <input type="checkbox" onchange="ChangeCheck(this);" name="itemsId" value="@deleteObj.Id">
                        </td>
                        <td>
                            <a href="@GetUrl(deleteObj.Type, deleteObj.Id)">@deleteObj.Name</a>
                        </td>
                        <td>
                            @deleteObj.DateCreate.ToString("dd MMMM yyyy HH:mm")
                        </td>
                        <td>
                            @deleteObj.DateDelete
                        </td>
                        <td>
                            <div class="btn-group">
                                <button class="btn" rel="tooltip" type="button" data-original-title="Восстановить" onclick="location.href='@Url.Action("RestoreItem", "Clients", new { pagesize, query, page = Model.PageNumber, restoreId = deleteObj.Id })'">
                                    <i class="icon-undo"></i>
                                </button>
                                <button class="btn" data-toggle="modal" rel="tooltip" type="button"
                                    onclick="location.href='@Url.Action("ForeverDeleteItem", "Clients", new { pagesize, query, page = Model.PageNumber, deleteId = deleteObj.Id })'" data-original-title="Удалить из корзины">
                                    <i class="icon-trash"></i>
                                </button>
                            </div>
                        </td>
                    </tr>
                    }
                }
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="100%">
                        <div class="table-toolbar">
                            <div class="quant-item pull-left">
                                @Html.DropDownListFor(x => x.PageSize, Model.ListForPageSize, new { @class = "input-mini", onchange = "Filter();" })
                                <span class="help-inline">записей на странице</span>
                            </div>
                            <div class="pagination pagination-right">
                                <ul>
                                    @Html.Paging(Model.PageNumber, Model.PageCount, i => Url.Action("Trash", "Clients", new { page = i, pagesize, query }))
                                </ul>
                            </div>
                        </div>
                    </td>
                </tr>
            </tfoot>
        </table>
        <div class="btn-toolbar">
            <button class="btn btn-primary" type="button" onclick="ClearThrash();">
                Очистить корзину</button>
            <button class="btn" type="button" name="delete" state="watch" onclick="DeleteOrRestoreSelected(this);">
                Удалить отмеченные</button>
            <button class="btn" type="button" state="watch" name="restore" onclick="DeleteOrRestoreSelected(this);">
                Восстановить отмеченные</button>
        </div>
    </div>
</div>
<script type="text/javascript">
    allCheckboxes = $("tbody .col-1 input[type=checkbox]");
</script>
